<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php $_option = $this->getOption(); ?>
<?php $_fileInfo = $this->getFileInfo(); ?>
<?php $_fileExists = $_fileInfo->hasData(); ?>
<?php $_fileName = 'options_' . $_option->getId() . '_file'; ?>
<?php $_fieldNameAction = $_fileName . '_action'; ?>
<?php $_fieldValueAction = $_fileExists ? 'save_old' : 'save_new'; ?>
<?php $_fileNamed = $_fileName . '_name'; ?>
<?php $class = ($_option->getIsRequire()) ? ' required' : ''; ?>

<div class="field file<?php echo $class; ?>">
    <label class="label">
        <span><?php echo  $this->escapeHtml($_option->getTitle()) ?></span>
        <?php echo $this->getFormatedPrice() ?>
    </label>
    <?php if ($_fileExists): ?>
    <div class="control">
        <span class="<?php echo $_fileNamed ?>"><?php echo $_fileInfo->getTitle(); ?></span>
        <a href="javascript:void(0)" class="label" id="change-<?php echo $_fileName ?>" >
            <?php echo __('Change') ?>
        </a>
        <?php if (!$_option->getIsRequire()): ?>
            <input type="checkbox" id="delete-<?php echo $_fileName ?>" />
            <span class="label"><?php echo __('Delete') ?></span>
        <?php endif; ?>
    </div>
    <?php endif; ?>
    <div class="control" id="input-box-<?php echo $_fileName ?>"
             data-mage-init='{"fileOption":{
                "fileName":"<?php echo $_fileName ?>",
                "fileNamed":"<?php echo $_fileNamed ?>",
                "fieldNameAction":"<?php echo $_fieldNameAction ?>",
                "changeFileSelector":"#change-<?php echo $_fileName ?>",
                "deleteFileSelector":"#delete-<?php echo $_fileName ?>"}
             }'
            <?php echo $_fileExists ? 'style="display:none"' : '' ?>>
        <input type="file"
               name="<?php echo $_fileName; ?>"
               class="product-custom-option<?php echo $_option->getIsRequire() ? ' required' : '' ?>"
               <?php echo $_fileExists ? 'disabled="disabled"' : '' ?> />
        <input type="hidden" name="<?php echo $_fieldNameAction; ?>" value="<?php echo $_fieldValueAction; ?>" />
        <?php if ($_option->getFileExtension()): ?>
            <p class="note">
                <?php echo __('Allowed file extensions to upload')?>: <strong><?php echo $_option->getFileExtension() ?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeX() > 0): ?>
            <p class="note">
                <?php echo __('Maximum image width')?>: <strong><?php echo $_option->getImageSizeX() ?> <?php echo __('px.')?></strong>
            </p>
        <?php endif; ?>
        <?php if ($_option->getImageSizeY() > 0): ?>
            <p class="note">
                <?php echo __('Maximum image height')?>: <strong><?php echo $_option->getImageSizeY() ?> <?php echo __('px.')?></strong>
            </p>
        <?php endif; ?>
    </div>
</div>
